package com.api.config;

import com.api.interceptor.AuthorizationInterceptor;
import com.api.interceptor.RequestInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @packageName: com.api.config
 * @name: WebConfig
 * @description:
 * @author: 董定卓
 * @dateTime: 2019/6/14 11:38
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    RequestInterceptor requestInterceptor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("http://127.0.0.1:8848", "http://dongdingzhuo.gitee.io");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(requestInterceptor).addPathPatterns("/**");
        registry.addInterceptor(new AuthorizationInterceptor()).addPathPatterns("/**");
    }

}
